<template>
  <div class="edit credit">
    <Form ref="product" :model="product" :rules="ruleValidate" :label-width="120">
      <h2 class="title">到期前2天</h2>
      <FormItem label="模板" prop="name">
        <Input v-model="product.name" type="textarea" :autosize="{minRows: 3,maxRows: 5}" placeholder="请输入短信内容模板"></Input>
      </FormItem>
      <FormItem label="	次数" prop="money">
        <Input v-model="product.money" number>
        </Input>
      </FormItem>
      <FormItem label="	时间" prop="money">
        <DatePicker type="date"   placeholder="选择时间" style="width:240px"></DatePicker>
      </FormItem>
       <FormItem >
        <Button @click="cancel" style="margin-right:5px">取消</Button>
        <Button type="primary" @click="ok">确定</Button>
      </FormItem>
       <h2 class="title">到期前1天</h2>
      <FormItem label="模板" prop="name">
        <Input v-model="product.name" type="textarea" :autosize="{minRows: 3,maxRows: 5}" placeholder="请输入短信内容模板"></Input>
      </FormItem>
      <FormItem label="	次数" prop="money">
        <Input v-model="product.money" number>
        </Input>
      </FormItem>
      <FormItem label="	时间" prop="money">
         <DatePicker type="date"   placeholder="选择时间" style="width:240px"></DatePicker>
      </FormItem>
       <FormItem >
        <Button @click="cancel" style="margin-right:5px">取消</Button>
        <Button type="primary" @click="ok">确定</Button>
      </FormItem>
        <h2 class="title">到期当天</h2>
      <FormItem label="模板" prop="name">
        <Input v-model="product.name" type="textarea" :autosize="{minRows: 3,maxRows: 5}" placeholder="请输入短信内容模板"></Input>
      </FormItem>
      <FormItem label="	次数" prop="money">
        <Input v-model="product.money" number>
        </Input>
      </FormItem>
      <FormItem label="	时间" prop="money">
        <DatePicker type="date"   placeholder="选择时间" style="width:240px"></DatePicker>
      </FormItem>
 <FormItem >
        <Button @click="cancel" style="margin-right:5px">取消</Button>
        <Button type="primary" @click="ok">确定</Button>
      </FormItem>
    <h2 class="title">逾期1天</h2>
      <FormItem label="模板" prop="name">
       <Input v-model="product.name" type="textarea" :autosize="{minRows: 3,maxRows: 5}" placeholder="请输入短信内容模板"></Input>
      </FormItem>
      <FormItem label="	次数" prop="money">
        <Input v-model="product.money" number>
        </Input>
      </FormItem>
      <FormItem label="	时间" prop="money">
         <DatePicker type="date"   placeholder="选择时间" style="width:240px"></DatePicker>
      </FormItem>
       <FormItem >
        <Button @click="cancel" style="margin-right:5px">取消</Button>
        <Button type="primary" @click="ok">确定</Button>
      </FormItem>
     <h2 class="title">逾期2天</h2>
      <FormItem label="模板" prop="name">
       <Input v-model="product.name" type="textarea" :autosize="{minRows: 3,maxRows: 5}" placeholder="请输入短信内容模板"></Input>
      </FormItem>
      <FormItem label="	次数" prop="money">
        <Input v-model="product.money" number>
        </Input>
      </FormItem>
      <FormItem label="	时间" prop="money">
        <DatePicker type="date"   placeholder="选择时间" style="width:240px"></DatePicker>
      </FormItem>
      <!--<FormItem label="商户Id" prop="merchantId">
        <Select clearable  v-model="product.merchantId">
          <Option
            v-for="item in typeList"
            :value=item.id
            :key="item.id"
          >{{ item.merchantName}}</Option>
        </Select>
      </FormItem>-->
      <FormItem >
        <Button @click="cancel" style="margin-right:5px">取消</Button>
        <Button type="primary" @click="ok">确定</Button>
      </FormItem>
    </Form>
  </div>
</template>

<script>
export default {
  data() {
    return {
      tag: {
        title: "到期短信提醒配置",
        path: "/work/messageSend/edit"
      },
      type:1,
      typeList: [],
      statusList:[//0未发布1发布2下架
       /* {
          id:0,
          name:'未发布 '
        },*/
        {
          id:1,
          name:'上架 '
        },
        {
          id:2,
          name:'下架 '
        }
        ],
      product: {
        // status:1
      },
      ruleValidate: {
        name: [{ required: true, message: "请填写产品名称", trigger: "blur" , }],
        money: [{ required: true, message: "请填写金额", trigger: "blur" ,type:'number'}],
        repayInterest: [
          { required: true, message: "请填写利息", trigger: "blur", type:'number' }
        ],
        serviceCharge: [
          { required: true, message: "请填写服务费", trigger: "blur", type:'number' }
        ],
        totalCost: [
          { required: true, message: "请填写总费用", trigger: "blur", type:'number' }
        ],
        day: [{ required: true, message: "请填写产品天数", trigger: "blur" ,type:'number'}],
        dayRate: [
          { required: true, message: "请填写基准日利率", trigger: "blur" ,type:'number'},
           {validator: (rule,value,callback) =>{
             if(value > 1){
               console.log('rate');
               callback(new Error('利率仅限0～1'))
             }
             callback();
           }, trigger: 'blur'}
        ],
        poundageRate: [
          { required: true, message: "请填写手续费利率", trigger: "blur" ,type:'number'},
          {validator: (rule,value,callback) =>{
             if(value > 1){
               console.log('rate');
               callback(new Error('利率仅限0～1'))
             }
             callback();
           }, trigger: 'blur'}
        ],
        overdueDayRate: [
          { required: true, message: "请填写逾期日利率", trigger: "blur" ,type:'number'},
          {validator: (rule,value,callback) =>{
             if(value > 1){
               console.log('rate');
               callback(new Error('利率仅限0～1'))
             }
             callback();
           }, trigger: 'blur'}
        ],
        penaltyDayRate: [
          { required: true, message: "请填写违约日利率", trigger: "blur" ,type:'number'},
          {
            validator: (rule,value,callback) =>{
             if(value > 1){
               console.log('rate');
               callback(new Error('利率仅限0～1'))
             }
             callback();
           },
           trigger: 'blur'
           }
        ],
    /*    merchantId: [
          { required: true, message: "请选择商户名称", trigger: "blur" ,type:'number'}
        ],*/
        status: [
          { required: true, message: "请选择显示状态", trigger: "blur" ,type:'number'}
        ]
      }
    };
  },
  mounted() {
    //this.product = this.$route.query.product;
    this.$post('/bkmerchant/list').then(res => {
      if(res.code == 0){
        this.typeList=res.data.pageListData;
        console.log( this.typeList,'type');
      }
    })
    this.$store.commit('changeTag', this.tag.path);
    this.$store.commit('openPage', this.tag);
  },
  methods: {
    resetValidate(name) {
      //清空判断
      this.$refs[name].resetFields();
    },
    ok() {
      //确定
      let url = "";
      this.$refs["product"].validate(valid => {
        if (valid) {
          let data = {
            id:this.product.id,
            name:this.product.name,
            money:this.product.money,
            realMoney:this.product.realMoney,
            day:this.product.day,
            dayRate:this.product.dayRate,
            repayInterest:this.product.repayInterest,
            serviceCharge:this.product.serviceCharge,
            totalCost:this.product.totalCost,
            poundageRate:this.product.poundageRate,
            overdueDayRate:this.product.overdueDayRate,
            penaltyDayRate:this.product.penaltyDayRate,
            // merchantId:this.product.merchantId,
            status: this.product.status
          };
          if (this.$route.query.title == "新增产品") {
            url = "/bkproduct/append";
          } else if (this.$route.query.title == "编辑产品") {
            url = "/bkproduct/modify";
          }
          this.$post(url, data).then(
            res => {
              if (res.code === 0) {
                console.log(res, "edit");
                this.$Message.success(`${this.$route.query.title}成功！`);
                this.$router.push({path:'/work/credit/list'})
              }
            },
            err => {
              console.log(err);
            }
          );
        }
      });
    },
    cancel() {
      // this.$router.push({path:'/work/credit/list'})
      this.resetValidate("product");
    }
  }
};
</script>

<style scoped lang="less">
.edit {
  width: 50%;
}
.ivu-input-group .ivu-input {
  text-align: center;
}
.ivu-input-group-prepend,
.ivu-input-group-append {
  width: 36px !important;
}
.credit {
  h2,h3 {
    margin-bottom: 15px;
    margin-left: 10px;
    border-left: solid 3px #20a0ff;
    padding-left: 15px;
    font-weight: bolder;
    font-size: 16px;
    color: #000;
  }
  h2{
    font-size: 14px;
  }
}
</style>
